package com.oa.login.dao;

import com.oa.login.entity.Emp;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;


@MapperScan
public interface EmpMapper {
    @Delete({
        "delete from emp",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into emp (id, emp_name, ",
        "emp_tel, user_id)",
        "values (#{id,jdbcType=INTEGER}, #{empName,jdbcType=VARCHAR}, ",
        "#{empTel,jdbcType=VARCHAR}, #{userId})"
    })
    int insert(Emp record);

    int insertSelective(Emp record);

    @Select({
        "select",
        "id, emp_name, emp_tel, user_id",
        "from emp",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.oa.login.dao.EmpMapper.BaseResultMap")
    Emp selectByPrimaryKey(Integer id);
    
    @Select({
        "select",
        "id, emp_name, emp_tel, user_id",
        "from emp",
        "where user_id = #{userId,jdbcType=INTEGER}"
    })
    @ResultMap("com.oa.login.dao.EmpMapper.BaseResultMap")
    Emp findByfk(int userId);

    int updateByPrimaryKeySelective(Emp record);

    @Update({
        "update emp",
        "set emp_name = #{empName,jdbcType=VARCHAR},",
          "emp_tel = #{empTel,jdbcType=VARCHAR},",
          "user_id = #{userId}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Emp record);
    
    
    @ResultMap("com.oa.login.dao.EmpMapper.BaseResultMap")
    @Select("select emp_name ,user_id from emp where emp_name not in ('admin',#{name})")
    List<Emp> findAll(String name);
    
    @Select("select emp_name from emp where emp_name <> 'admin'")
    String[] findNames();
    
    @ResultMap("com.oa.login.dao.EmpMapper.BaseResultMap")
    @Select("select * from emp")
    List<Emp> findAlls();
    
    @Delete("delete from emp where user_id=#{id}")
    int del(int id);
}